package org.jdpf.gui.rcp.neteditor.core.elements;

import org.eclipse.swt.graphics.Point;

public abstract class AbstractGraphicNode implements IGraphicNode {

	protected Point position;
	protected int height;
	protected IGraphicNode attachedNode;
	
	public void attachNode(IGraphicNode node) {
		this.attachedNode = node;
	}

	protected int width;
	
	public int getHeight() {
		return height;
	}

	public int getWidth() {
		return width;
	}

	public Point getPosition() {
		return position;
	}
	
	public boolean isSelected(Point point) {
		boolean flag = false;
		if (point.x > position.x && point.x < position.x + width) {
			if (point.y > position.y && point.y < position.y + height) {
				flag = true;
			}
		}
		return flag;
	}

	public void setPositionCenter(Point center) {
		Point pointC = new Point(center.x - (width / 2), center.y
				- (height / 2));
		setPosition(pointC);
	}

	public void setPosition(Point point) {
		this.position = point;
		if(attachedNode!=null)
			attachedNode.setPosition(this.position);
	}
}
